﻿using QaaSimulation.QSim.Ships.Editor;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QaaSimulation
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            FormClosing += Form1_FormClosing;
        }

        void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            qSpaceControl1.timer.Stop();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // battlefield1.timer.Start();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //battlefield1.timer.Start();
            qSpaceControl1.timer.Start();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            QShipModelEditor d = new QShipModelEditor();
            d.ShowDialog();
            qSpaceControl1.m_PlayerShip.Model = d.EditorControl.BoundModel;
            
        }
    }

    

    public static class QFunctions
    {
        public static float Length(Point p)
        {
            return (float)Math.Sqrt(p.X * p.X + p.Y * p.Y);
        }

        public static float Length(Point p1, Point p2)
        {
            return Length(new Point(p2.X - p1.X, p2.Y - p1.Y));
        }

        public static float Length(PointF p)
        {
            return (float)Math.Sqrt(p.X * p.X + p.Y * p.Y);
        }

        public static float Length(PointF p1, PointF p2)
        {
            return Length(new PointF(p2.X - p1.X, p2.Y - p1.Y));
        }

        public static float Dot(PointF p1, PointF p2)
        {
            return p1.X * p2.X + p1.Y * p2.Y;
        }

        public static float LengthSq(PointF p)
        {
            float res = (float)Math.Sqrt(p.X * p.X + p.Y * p.Y);
            return res * res;
        }

        public static float LengthSq(PointF p1, PointF p2)
        {
            return LengthSq(new PointF(p2.X - p1.X, p2.Y - p1.Y));
        }

        public static int SolveQuadratic(float A, float B, float C, ref float[] r)
        {
            float p = B / A;
            float q = C / A;

            float D = p * p - 4 * q;

            if (D <= 0)
            {
                return 0;
            }

            float x1 = (-B + (float)(Math.Sqrt(B * B - 4 * A * C))) / (2 * A);
            float x2 = (-B - (float)(Math.Sqrt(B * B - 4 * A * C))) / (2 * A);
            r[0] = x1;
            r[1] = x2;
            return 2;
        }
    }

}
